package com.j180.converter;

import org.springframework.core.convert.converter.Converter;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class StringToLocalDate implements Converter<String, LocalDate> {
    
    @Override
    public LocalDate convert(String s) {
        return (s != null && s.matches("\\d{4}-((0[1-9])|(1[0-2]))-(([0-2][0-9])|(3[01]))"))
                ? LocalDate.parse(s, DateTimeFormatter.ofPattern("yyyy-MM-dd")) : LocalDate.now() ;
    }
}

